#include "widget.h"
#include "ui_widget.h"


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    labelshapeArea = new PainterArea; //控制面板的布局
    setWindowTitle("Qt绘图框架测试: QPainter类");

    labelshape = new QLabel("绘制形状: ");
    comboboxshape = new QComboBox;
    comboboxshape->addItem("Line", PainterArea::Line);
    comboboxshape->addItem("Rectangle", PainterArea::Rectangle);

    //connect(comboboxshape, &QComboBox::activated, this, &Widget::dispShapeFunc);

    glayout->addWidget(labelshape,0,0);
    glayout->addWidget(comboboxshape,0,1);

    QHBoxLayout *mainlayout=new QHBoxLayout(this); // 整体布局
    mainlayout->addWidget(labelshapeArea); // 向布局添加控件
    mainlayout->addLayout(glayout); // 向整体布局添加布局

    // 如下语句大家自己添加
    dispShapeFunc(comboboxshape->currentIndex());//显示默认的图形
}


Widget::~Widget()
{
    delete ui;
}



void Widget::dispShapeFunc(int v)
{
    PainterArea::shape sp=PainterArea::shape(comboboxshape->itemData(v,Qt::UserRole).toInt());
    labelshapeArea->setShape(sp);
}
